import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
  {
    name: 'fullscreen',
    component: () => import('./view/fullscreen'),
    meta: {
      title: '石钢木节能系统'
    }
  },
  {
    name: '/',
    component: () => import('./view/home'),
    meta: {
      title: '石钢木节能系统'
    }
  },
  {
    name: 'water',
    component: () => import('./view/water'),
    meta: {
      title: '石钢木节能系统'
    }
  },
  {
    name: 'chart',
    component: () => import('./view/chart'),
    meta: {
      title: '石钢木节能系统'
    }
  },
  {
    name: 'login',
    component: () => import('./view/login'),
    meta: {
      title: '登录'
    }
  }
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({
  mode: 'history',
  base: '/front/',
  routes: routes
});

router.beforeEach((to, from, next) => {
  if (window.innerWidth > 768) {
    location.href = '/admin/#/?token=' + to.query.token
  } 
  next()
});

export {
  router
};
